package com.bigintegerdemo;

import java.math.BigInteger;

public class BigIntegerDemo2 {
    public static void main(String[] args) {
        /*
        public BigInteger add(BigInteger val)                       加法
        public BigInteger subtract(BigInteger val)                  减法
        public BigInteger multiply(BigInteger val)                  乘法
        public BigInteger divide(BigInteger val)                    除法，获取商
        public BigInteger[] divideAndRemainder(BigInteger val)      除法，获取商和余数
        public boolean equals(object x)                             比较是否相同
        publicBigInteger pow(int exponent)                          次幂
        public BigInteger max/ min(BigInteger val)                  返回较大值/较小值
        public int intValue(BigInteger val)                         转为int类型整数，超出范围数据有误
         */
        //1.创建两个BigInteger的对象
        BigInteger bigInteger1 = BigInteger.valueOf(10);
        BigInteger bigInteger2 = BigInteger.valueOf(3);

        //2.加法
        BigInteger bigInteger3 = bigInteger1.add(bigInteger2);
        System.out.println(bigInteger3);
        System.out.println("=========");

        //3.除法，获取商和余数
        BigInteger[] bigIntegers = bigInteger1.divideAndRemainder(bigInteger2);
        System.out.println(bigIntegers.length);
        System.out.println(bigIntegers[0]);
        System.out.println(bigIntegers[1]);
        System.out.println("=========");

        //4.比较是否相同
        boolean flag = bigInteger1.equals(bigInteger2);
        System.out.println(flag);
        System.out.println("=========");

        //5.次幂
        BigInteger bigInteger4 = bigInteger1.pow(2);
        System.out.println(bigInteger4);
        System.out.println("=========");

        //6.max
        BigInteger bigInteger5 = bigInteger1.max(bigInteger2);
        System.out.println(bigInteger5);
        System.out.println(bigInteger1==bigInteger5);
        System.out.println(bigInteger2==bigInteger5);
        System.out.println("=========");

        //7.转为int类型整数，超出范围数据有误
        BigInteger bigInteger6 = BigInteger.valueOf(1000);
        int value = bigInteger6.intValue();
        System.out.println(value);
        long value1 = bigInteger6.longValue();
        System.out.println(value1);
        double value2 = bigInteger6.doubleValue();
        System.out.println(value2);
    }
}
